home *** CD-ROM | disk | FTP | other *** search
/ PC Media 23 / PC MEDIA CD23.iso / share / prog / anubis / colae.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-10  |  1.5 KB  |  67 lines

  1. #ifndef COLAE.H
  2.  
  3. #define COLAE.H
  4.  
  5. // Cola de enteros, este algoritmo simula una cola de enteros.
  6.  
  7. #include "mdefs.h"
  8.  
  9. #include <conio.h>
  10.  
  11. #include <stdlib.h>
  12.  
  13. #include <alloc.h>
  14.  
  15.  
  16.  
  17.  
  18.  
  19. typedef struct  {
  20.  
  21.    void *Siguiente;
  22.  
  23.    int entero;
  24.  
  25. } ElementoColaEnteros;
  26.  
  27.  
  28.  
  29. typedef struct {
  30.  
  31.    ElementoColaEnteros *Inicio;
  32.  
  33.    ElementoColaEnteros *Fin;
  34.  
  35. } ColaE;
  36.  
  37.  
  38.  
  39. typedef ElementoColaEnteros *pColaE;
  40.  
  41.  
  42.  
  43.  
  44.  
  45. #define COLAE_TODO_OK                0
  46.  
  47. #define COLAE_MEMORIA_INSUFICIENTE   1
  48.  
  49.  
  50.  
  51. #define ColaEVacia(x)    ( ((*x).Fin) == NULL)
  52.  
  53. #define ColaETope(x)     ((x->entero)
  54.  
  55.  
  56.  
  57.  
  58.  
  59. void ColaEAnula( ColaE *cola)
  60.  
  61. {
  62.  
  63.    (*cola).Inicio = NULL;
  64.  
  65.    (*cola).Fin = NULL;
  66.  
  67. }// end ColaGenericaAnula
  68.  
  69.  
  70.  
  71. WORD ColaEMete(ColaE *cola, int numero)
  72.  
  73. {
  74.  
  75.    pColaE elem;
  76.  
  77.  
  78.  
  79.    elem= (pColaE) malloc(sizeof(ElementoColaEnteros));
  80.  
  81.    if( elem != NULL)  {
  82.  
  83.       (*elem).entero = numero;
  84.  
  85.       (*elem).Siguiente = NULL;
  86.  
  87.       if( ColaEVacia(cola))  {
  88.  
  89.          (*cola).Fin = elem;
  90.  
  91.          (*cola).Inicio = elem;
  92.  
  93.       }  else  {
  94.  
  95.          (*((*cola).Inicio)).Siguiente = elem;
  96.  
  97.          (*cola).Inicio= elem;
  98.  
  99.       }// end if
  100.  
  101.       return(COLAE_TODO_OK);
  102.  
  103.    }  else
  104.  
  105.       return (COLAE_MEMORIA_INSUFICIENTE);
  106.  
  107. }// end ColaGenericaMete
  108.  
  109.  
  110.  
  111. int ColaESaca(ColaE *cola)
  112.  
  113. {
  114.  
  115.    pColaE elem= cola->Fin;
  116.  
  117.    int numero = elem->entero;
  118.  
  119.    (*cola).Fin = elem->Siguiente;
  120.  
  121.    if ( (*cola).Fin == NULL)
  122.  
  123.       (*cola).Inicio = NULL;
  124.  
  125.    free(elem);
  126.  
  127.    return(numero);
  128.  
  129. }// end ColaGenericaSaca
  130.  
  131.  
  132.  
  133. #endifdefine ColaG